﻿using System.Text.Json.Serialization;
using Core.Domain.Enums;
using Core.Domain.ValueObjects;

namespace Core.Identity.Users.Dtos;

/// <summary>
/// 用户信息
/// </summary>
public class UserDto
{
    /// <summary>
    /// 主键
    /// </summary>
    public Guid Id { get; set; }
    /// <summary>
    /// 用户账号
    /// </summary>
    public string? Username { get; set; }
    /// <summary>
    /// 昵称
    /// </summary>
    public string? Nickname { get; set; }
    /// <summary>
    /// 头像
    /// </summary>
    public Avatar? Avatar { get; set; }
    /// <summary>
    /// 邮箱
    /// </summary>
    public string? Email { get; set; }
    /// <summary>
    /// 邮箱确认
    /// </summary>
    public bool? EmailConfirmed { get; set; }
    /// <summary>
    /// 手机号码
    /// </summary>
    public PhoneNumber? PhoneNumber { get; set; }
    /// <summary>
    /// 确认手机
    /// </summary>
    public bool? PhoneNumberConfirmed { get; set; }
    /// <summary>
    /// 开启双因子
    /// </summary>
    public bool? TwoFactorEnabled { get; set; }
    /// <summary>
    /// 账号锁定
    /// </summary>
    public UserLockout? Lockout { get; set; }
    /// <summary>
    /// 状态
    /// </summary>
    public bool? Enabled { get; set; }
    /// <summary>
    /// 性别
    /// </summary>
    public GenderType? Gender { get; set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTimeOffset? Created { get; set; }

    /// <summary>
    /// 设置描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 个性签名
    /// </summary>
    public string? Signature { get; set; }

    [JsonIgnore]
    public List<UserOrganizationDto>? UserOrganizations { get; set; } = new List<UserOrganizationDto>();
    /// <summary>
    /// 组织ID
    /// </summary>
    public Guid? OrganizationId
    {
        get
        {
            if (UserOrganizations != null && UserOrganizations.Any())
            {
                return UserOrganizations.First().OrganizationId;
            }
            return null;
        }
    }
    /// <summary>
    /// 组织名称
    /// </summary>
    public string? OrganizationName
    {
        get
        {
            if (UserOrganizations != null && UserOrganizations.Any())
            {
                return UserOrganizations.First().Organization?.Name;
            }
            return null;
        }
    }
}

public class UserOrganizationDto
{
    public Guid OrganizationId { get; set; }
    public OrganizationDto? Organization { get; set; }
}

public class OrganizationDto
{
    public string? Name { get; set; }
}
